package com.framework.dubbo.producer.file2html;

import cn.hutool.core.util.StrUtil;

/**
 * 文件处理
 * @author xianggj
 * @Date 2021/6/8 15:44
 **/
public class FilePreviewFactory {

    /**
     * 根据类型获取处理类
     * @param fileType
     */
    public static AbstractFilePreviewTools getToolByType(FileType fileType) {
        AbstractFilePreviewTools afpt = null;
        switch (fileType.getType()) {
            case 1:
                afpt = new StringFilePreviewUtil();
                break;
            case 2:
                afpt = getTool(fileType);
                break;
            case 3:
                afpt = new ZipFilePreviewUtil();
                break;
            case 4:
                afpt = new ImgPreviewUtil();
                break;
            case 5:
                afpt = new PathPreviewUtil();
                break;
            case 6:
                afpt = new HtmlPreviewUtil();
                break;
            case 7:
                afpt = new SourcePreviewUtil();
                break;
            default:

        }
        return afpt;
    }

    /**
     * 文档类文件处理类
     * @param fileType
     * @return
     */
    private static AbstractFilePreviewTools getTool(FileType fileType ){
        switch (fileType) {
            case CSV:
                return new CsvFilePreviewUtil();
            case PPT:
            case PPTX:
                return new AsposePPTFilePreviewUtil();
            case XLS:
            case XLSX:
                return new ExcelFilePreviewer();
            case DOC:
            case DOCX:
                return new WordFilePreviewer();
            default:

        }
        return null;
    }


    /**
     * 截取文件类型
     * @param path
     * @return
     */
    public static String getExt(String path) {
        if (path.contains(".")){
            return StrUtil.subAfter(path, ".", true);
        }
        return path;
    }
}
